About LiveConnect
LiveConnect is the name of a technology used by the Netscape Corporation in Navigator 3.0.
LiveConnect makes it possible for plugins, Java applets, and JavaScript within the same page to communicate with each other, allowing more highly interactive home pages to be created with a greater degree of freedom.
MIDPLUG can use JavaScript to take advantage of LiveConnect functionality. JavaScript is a scripting language that makes it possible to add diverse functionality to a home page that would not be possible using HTML alone, and can be written directly into an HTML file.
(It is not possible to discuss the details of JavaScript here, so please refer to the books or home pages which discuss it. Here we will discuss some examples of calling MIDPLUG functionality.)
More information about LiveConnect and JavaScript is in the Netscape's Homepage
MIDPLUG can be controlled by defining the following MIDPLUG functionality as methods (functions), and then calling them from JavaScript.The following functions are defined as methods.
play(loop[True or False],'url_to_song') | The same function as the Play button. üEloop will loop when true. üEurl_to_song gives the URL of the song data to be played back. üEParameters can be omitted, and in this case, 'loop' will be true, and playback will refer to the currently loaded data. |
stop() | Same function as the Stop button. |
pause() | Same function as the Pause button. |
setvol(int percent) | Specify the volume as an integer. |
volumeup() | Same function as the Volume Up button. |
volumedown() | Same function as the Volume Down button. |
tempoup() | Same function as the Tempo Up |
temporeset() | Same function as the Tempo Reset |
tempodown() | Same function as the Tempo Down |
pitchup() | Same function as the Transpose Up |
pitchreset() | Same function as the Transpose Reset |
pitchdown() | Same function as the Transpose Down |
IsReady() | When the plugin is ready to run, this will always return a value of "True" |
IsPlaying() | While a song is playing, this will return a value of "True" |
IsPause() | While the song is paused, this will return a value of "True" |
GetVolume() | This gets the current volume |
Sample HTML using LiveConnect is given below. Copy&Paste this to the SimpleText etc. for your own use.In addition to the control panel, this will display "Play" and "Stop" in the browser, and MIDPLUG can be controlled by clicking on these. (Look at the control panel and you will see that the operation is linked.)
(* Place the name of the MIDI file that you are providing in the 'xxxxxx.mid' portion.)
<html>
|
In the above "head" tag,
<script language="Javascript">
</script>
is the tag for writing JavaScript. The JavaScript is written within this tag.
<!--
//-->
is a provision for browsers which do not support JavaScript. If you include this tag, JavaScript written inside the tag will be handled as a comment by browsers which do not support JavaScript.
Now we come to the content of the script. First, the "head" tag defines the methods (functions) which will be used in this page.
In the section
function play_sound(){
document.embeds[0].play('testsong.mid')
}
"function play_sound()" is a declaration that "play_sound()" is a method (function).
The contents of this method (function) are given in the { } which follow it. Let's take a look inside the { }.
The contents of the { } are
document.embeds[0].play('testsong.mid')
In JavaScript, "document" refers to the HTML file which contains the JavaScript instructions.
Next comes "embeds[0]". This refers to the plugin which is actually called by "embed". In this case, this will be MIDPLUG.
The "[0]" indicates the embed portion that is written in the very top of that page. If the same page contains another "embed" tag, it would be specified as "embed[1]". In other words, the numbers begin from 0.
Next is "play('testsong.mid')," which is a playback method for MIDPLUG, which was defined in the table above.
These three are connected by periods. The meaning of the entire line could be expressed as "Execute the play() method of the plugin which is embedded in the first part of this page. The song to be played is 'testsong.mid'."
Next we have
function stop_sound(){
document.embeds[0].stop()
}
which can be interpreted in the same way:
"the function stop_sound() executes the stop() method of the plugin which is embedded in the first part of this page."
The methods (functions) used by this page have now been defined.
The timing at which these methods are called are specified within the "body" tag. This is the section which reads as follows:
<a href="javascript:play_sound("testsong.mid')">Play</a>
<a href="javascript:stop_sound()">Stop</a>
After <a href=>we would normally specify the link destination, and by pressing the area between it and</a>(in this case "Play") we would jump to that link destination.However with the code given above, we instead call the method (function) which was defined in the "head" tag that was given earlier. This means that when you press "Play," what will happen is that"The play() method of the plugin which is embedded in the first part of this page will be executed. The song to be played is 'testsong.mid'."
and MIDPLUG will begin playback of the song.
Pressing "Stop" will have a similar result.
The above example is the simplest possible one, but much more can be done with JavaScript, even without
It is possible to create a wide variety of pages using methods which MIDPLUG is able to receive. This may have been a bit difficult for some of you to follow, but please go ahead and try it for yourself, starting with something simple.The sample gallery at "XG by YAMAHA HOMEPAGE"contains some more involved examples, so study the source code and learn from it.
Back to Main |
---|